package pens.com
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.DisplayObject;
	import flash.display.Loader;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.net.URLRequest;
	
	import pens.factory.PenFactory;
	import pens.interfaces.IPenPlayer;
	
	/**
	 * @author 偷心枫贼
	 * @E-mail: 527025965@qq.com
	 * 创建时间：2013-8-24 下午8:33:47
	 * 
	 */
	public class PanelSignInImage extends Sprite
	{
		
			private var _w:Number
			private var _h:Number
			
			public function get w():Number{return _w}
			public function get h():Number{return _h}
			
		private var _pen:IPenPlayer

		private var bmp:Bitmap=new Bitmap()
		public function get pen():IPenPlayer{return _pen}
		public function PanelSignInImage(penName:String,w:Number=400,h:Number=300)
		{
			
			_w=w
			_h=h
			
		
				
				
				
				
				
				
				
				
			bmp.smoothing=true
			addChild(bmp);
			
			
			_pen=PenFactory(new PenFactory()).createPlayer(penName);
			//_pen.width=_w
		//	_pen.height=_h
			addChild(_pen as DisplayObject)
			
			
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE,CompleteHandler)
			loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,CompleteHandler)
		}
		private var loader:Loader=new Loader()
		private var _source:Object;
		public function get source():Object { return _source; }		
		public function set source(value:Object):void
		{
			if (_source == value)
				return;
			_source = value;
			
			if(_source is String){
				
				loader.load(new URLRequest(String(value)))
			}
			
		}
		
		private function CompleteHandler(e:Event):void{
			
			if(e.type!=IOErrorEvent.IO_ERROR){
			trace("加载成功")
				var bitm:BitmapData=new BitmapData(loader.content.width,loader.content.height,true,0xffffff)
				bitm.draw(loader.content)
				bmp.bitmapData=bitm;
				bmp.width=_w
				bmp.height=_h
				//	_pen.draw(_w,_h)
				//_pen.width=_w
			//	_pen.height=_h
			
			}
		}
		
		
		
		
	}
}